package com.dal.module.account.paramcheck;

import java.util.Map;

import org.error.LoginErrorCode;

import com.dal.constant.ParamKey;
import com.dal.constant.Patterns;
import com.jfinal.core.Controller;
import com.sojoys.artifact.exception.AbstractLogicModelException;
import com.sojoys.artifact.tools.ToolError;
import com.xiaoleilu.hutool.lang.Validator;

/**
 * Created by fxf on 2017/6/22.
 */
@SuppressWarnings({"unchecked","rawtypes"})
public class LocalTestParamChecker extends AbstractParamChecker {
    
	@Override
    public void platformParamCheck(Controller controller, Map outParam) throws AbstractLogicModelException {
        String activateKey = controller.getPara(ParamKey.ACTIVATE_KEY);
        if (activateKey != null && activateKey.length() > 0) {
            outParam.put(ParamKey.ACTIVATE_KEY, activateKey);
        }
        String accountId = controller.getPara(ParamKey.ACCOUNT_ID);
        String password = controller.getPara(ParamKey.PASSWORD);
    	ToolError.isAndTrue(LoginErrorCode.USER_NAME_INVALID,!Validator.isMactchRegex(Patterns.ACCOUNT_OR_PASSWORD, accountId));
    	ToolError.isAndTrue(LoginErrorCode.PASSWORD_INVALID,!Validator.isMactchRegex(Patterns.ACCOUNT_OR_PASSWORD, password));
        outParam.put(ParamKey.ACCOUNT_ID, accountId);
        outParam.put(ParamKey.PASSWORD, password);
    }
}

